home *** CD-ROM | disk | FTP | other *** search
/ mail.altrad.com / 2015.02.mail.altrad.com.tar / mail.altrad.com / TEST / office german / PROPLUS.WW / PROPLSWW.CAB / sql70.xsl.5DF9D670_534C_4AB2_B0C6_FF0B0C448C29 < prev    next >
Extensible Markup Language  |  2006-10-26  |  32KB  |  731 lines

  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0" xmlns:mssqlcrt="urn:sql-microsoft-com:sqlcrt" xmlns:mssqldbg="urn:sql-microsoft-com:sqldbg">
  3.     <xsl:output method="xml" indent="yes"/>
  4.  
  5.     <!-- This ALWAYS GENERATED file contains the definitions for the cartridges
  6.                  Microsoft Cartridge Interfaces (Analysis Services 2005)
  7.                  (C) Copyright 1988 - 2003 By Microsoft Corporation.      -->
  8.  
  9.     <!-- SQL Server 7.0 pluggable cartridge                              -->
  10.  
  11.     <!-- Area of STANDARD parametrizations: these are externally passed   -->
  12.     <xsl:param name="in_CanUseParams">yes</xsl:param>
  13.     <xsl:param name="in_IdentStartQuotingCharacter">[</xsl:param>
  14.     <xsl:param name="in_IdentEndQuotingCharacter">]</xsl:param>
  15.     <xsl:param name="in_StringStartQuotingCharacter">'</xsl:param>
  16.     <xsl:param name="in_StringEndQuotingCharacter">'</xsl:param>
  17.     
  18.     <!-- Area of CORE parametrizations: These are externally checked      -->
  19.     <mssqlcrt:provider type="prefix">Microsoft SQL Server.07</mssqlcrt:provider>
  20.  
  21.     <mssqlcrt:capabilities>
  22.         <mssqlcrt:supports-datepart-year/>
  23.         <mssqlcrt:supports-datepart-quarter/>
  24.         <mssqlcrt:supports-datepart-month/>
  25.         <mssqlcrt:supports-datepart-dayofyear/>
  26.         <mssqlcrt:supports-datepart-day/>
  27.         <mssqlcrt:supports-datepart-week/>
  28.         <mssqlcrt:supports-datepart-dayofweek/>
  29.         <mssqlcrt:supports-datepart-hour/>
  30.         <mssqlcrt:supports-datepart-minute/>
  31.         <mssqlcrt:supports-datepart-second/>
  32.         <mssqlcrt:supports-datepart-millisecond/>
  33.         <mssqlcrt:supports-multiple-distinct-count/>
  34.         <mssqlcrt:supports-update/>
  35.         <mssqlcrt:supports-insert/>
  36.         <mssqlcrt:supports-subselect/>
  37.         <mssqlcrt:supports-table-alias/>
  38.         <mssqlcrt:supports-column-alias/>
  39.         <mssqlcrt:supports-cast/>
  40.         <mssqlcrt:supports-remote-query/>
  41.         <mssqlcrt:supports-top-clause/>
  42.         <mssqlcrt:supports-union/>
  43.         <mssqlcrt:supports-union-all/>
  44.         <mssqlcrt:supports-fast-writeback>TABLOCK,FIRE_TRIGGERS</mssqlcrt:supports-fast-writeback>
  45.         <mssqlcrt:limit-table-identifier-length>128</mssqlcrt:limit-table-identifier-length>
  46.         <mssqlcrt:limit-column-identifier-length>128</mssqlcrt:limit-column-identifier-length>
  47.  
  48.         <!-- Map from MSDAInitialize connection string to SQLOLEDB connection string -->
  49.         <mssqlcrt:remote-connection-string-mappings>
  50.             <mssqlcrt:remote-connection-string-mapping>
  51.                 <mssqlcrt:datasource-property>Provider</mssqlcrt:datasource-property>
  52.                 <mssqlcrt:remote-property></mssqlcrt:remote-property>
  53.             </mssqlcrt:remote-connection-string-mapping>
  54.             <mssqlcrt:remote-connection-string-mapping>
  55.                 <mssqlcrt:datasource-property>Data Source</mssqlcrt:datasource-property>
  56.                 <mssqlcrt:remote-property>Server</mssqlcrt:remote-property>
  57.             </mssqlcrt:remote-connection-string-mapping>
  58.             <mssqlcrt:remote-connection-string-mapping>
  59.                 <mssqlcrt:datasource-property>Initial Catalog</mssqlcrt:datasource-property>
  60.                 <mssqlcrt:remote-property>Database</mssqlcrt:remote-property>
  61.             </mssqlcrt:remote-connection-string-mapping>
  62.             <mssqlcrt:remote-connection-string-mapping>
  63.                 <mssqlcrt:datasource-property>User ID</mssqlcrt:datasource-property>
  64.                 <mssqlcrt:remote-property>UID</mssqlcrt:remote-property>
  65.             </mssqlcrt:remote-connection-string-mapping>
  66.             <mssqlcrt:remote-connection-string-mapping>
  67.                 <mssqlcrt:datasource-property>Password</mssqlcrt:datasource-property>
  68.                 <mssqlcrt:remote-property>PWD</mssqlcrt:remote-property>
  69.             </mssqlcrt:remote-connection-string-mapping>
  70.             <mssqlcrt:remote-connection-string-mapping>
  71.                 <mssqlcrt:datasource-property>Integrated Security=SSPI</mssqlcrt:datasource-property>
  72.                 <mssqlcrt:remote-property>Trusted_Connection=yes</mssqlcrt:remote-property>
  73.             </mssqlcrt:remote-connection-string-mapping>
  74.         </mssqlcrt:remote-connection-string-mappings>
  75.     </mssqlcrt:capabilities>
  76.  
  77.     <mssqlcrt:schema-classes>
  78.         <mssqlcrt:schema-class>
  79.             <mssqlcrt:managed-provider>System.Data.SqlClient</mssqlcrt:managed-provider>
  80.             <mssqlcrt:type>Microsoft.DataWarehouse.Design.SqlSchema, Microsoft.DataWarehouse</mssqlcrt:type>
  81.             <mssqlcrt:query-designer>
  82.                 <mssqlcrt:type>Microsoft.DataWarehouse.Controls.SqlClientQueryDesigner, Microsoft.DataWarehouse</mssqlcrt:type>
  83.             </mssqlcrt:query-designer>
  84.         </mssqlcrt:schema-class>
  85.         <mssqlcrt:schema-class>
  86.             <mssqlcrt:managed-provider>System.Data.OleDb</mssqlcrt:managed-provider>
  87.             <mssqlcrt:type>Microsoft.DataWarehouse.Design.OleDbSchema, Microsoft.DataWarehouse</mssqlcrt:type>
  88.             <mssqlcrt:query-designer>
  89.                 <mssqlcrt:type>Microsoft.DataWarehouse.Controls.OleDbQueryDesigner, Microsoft.DataWarehouse</mssqlcrt:type>
  90.             </mssqlcrt:query-designer>
  91.         </mssqlcrt:schema-class>
  92.         <mssqlcrt:schema-class>
  93.             <mssqlcrt:managed-provider>System.Data.Odbc</mssqlcrt:managed-provider>
  94.             <mssqlcrt:type>Microsoft.DataWarehouse.Design.OdbcSchema, Microsoft.DataWarehouse</mssqlcrt:type>
  95.         </mssqlcrt:schema-class>
  96.     </mssqlcrt:schema-classes>
  97.     <!-- Area of internal parametrizations                                -->
  98.     <!-- overrideOfUseParams:
  99.              yes      = use always parametric queries
  100.              no       = never use parametric queries
  101.              nosubsel = use as yes, but not on subselects
  102.              auto     = use the value of in_CanUseParams to determine     -->
  103.     <xsl:variable name="overrideOfUseParams">auto</xsl:variable>
  104.     <!-- shouldProduceDebug:
  105.              yes      = produce debug information
  106.              no       = do not produce debug information                  -->
  107.     <xsl:variable name="shouldProduceDebug">yes</xsl:variable>
  108.  
  109.     <!-- Area of global variables initializations                         -->
  110.     <xsl:variable name="UseParams">
  111.         <xsl:choose>
  112.             <xsl:when test="normalize-space($overrideOfUseParams) = 'yes' or (normalize-space($overrideOfUseParams) = 'auto' and normalize-space($in_CanUseParams)='yes')">yes</xsl:when>
  113.             <xsl:when test="normalize-space($overrideOfUseParams) = 'nosubsel'">nosubsel</xsl:when>
  114.             <xsl:otherwise>no</xsl:otherwise>
  115.         </xsl:choose>
  116.     </xsl:variable>
  117.     <xsl:variable name="ProduceDebug" select="$shouldProduceDebug"/>
  118.     <xsl:variable name="IdentifierStartQuotingCharacter" select="normalize-space($in_IdentStartQuotingCharacter)"/>
  119.     <xsl:variable name="IdentifierEndQuotingCharacter" select="normalize-space($in_IdentEndQuotingCharacter)"/>
  120.     <xsl:variable name="StringStartQuotingCharacter" select="normalize-space($in_StringStartQuotingCharacter)"/>
  121.     <xsl:variable name="StringEndQuotingCharacter" select="normalize-space($in_StringEndQuotingCharacter)"/>
  122.  
  123.     <!-- Generated statement packaging                                    -->
  124.     <xsl:template match="/">
  125.         <xsl:element name="Statement">
  126.  
  127.             <!-- Generate query                                           -->
  128.             <xsl:element name="Text">
  129.                 <xsl:apply-templates select="./Statement/*[1]"/>
  130.             </xsl:element>
  131.  
  132.             <!-- Generate parameters                                      -->
  133.             <xsl:if test="count(./Statement/Parameters/Parameter)!=0 and ((normalize-space($UseParams)='yes') or (normalize-space($UseParams)='nosubsel'))">
  134.                 <xsl:element name="Parameters">
  135.                     <xsl:choose>
  136.                         <xsl:when test="/Statement/*[1]//Parameter/@ParamName">
  137.                             <xsl:for-each select="./Statement/Parameters/Parameter">
  138.                                 <xsl:element name="Parameter">
  139.                                     <xsl:attribute name="ref">
  140.                                         <xsl:value-of select="./@id"/>
  141.                                     </xsl:attribute>
  142.                                 </xsl:element>
  143.                             </xsl:for-each>
  144.                         </xsl:when>
  145.                         <xsl:otherwise>
  146.                             <xsl:for-each select="./Statement/*[1]//Parameter">
  147.                                 <xsl:element name="Parameter">
  148.                                     <xsl:attribute name="ref">
  149.                                         <xsl:value-of select="./@ref"/>
  150.                                     </xsl:attribute>
  151.                                 </xsl:element>
  152.                             </xsl:for-each>
  153.                         </xsl:otherwise>
  154.                     </xsl:choose>
  155.                 </xsl:element>
  156.             </xsl:if>
  157.  
  158.             <!-- Generate debug info                                      -->
  159.             <xsl:if test="$ProduceDebug='yes'">
  160.                 <xsl:element name="mssqldbg:DebugInfo">
  161.                     <xsl:element name="mssqldbg:GenerateParametricInfo">
  162.                         <xsl:attribute name="mssqldbg:Value">
  163.                             <xsl:value-of select="$UseParams"/>
  164.                         </xsl:attribute>
  165.                         <xsl:element name="mssqldbg:External">
  166.                             <xsl:value-of select="$in_CanUseParams"/>
  167.                         </xsl:element>
  168.                         <xsl:element name="mssqldbg:Internal">
  169.                             <xsl:value-of select="$overrideOfUseParams"/>
  170.                         </xsl:element>
  171.                     </xsl:element>
  172.                 </xsl:element>
  173.             </xsl:if>
  174.  
  175.         </xsl:element>
  176.     </xsl:template>
  177.  
  178.     <!-- Union statement                                                  -->
  179.     <xsl:template match="Union">
  180.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  181.             (
  182.         </xsl:if>
  183.             <xsl:call-template name="print-children-list">
  184.                 <xsl:with-param name="operator" select="' UNION '"/>
  185.             </xsl:call-template>
  186.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  187.             )
  188.         </xsl:if>
  189.     </xsl:template>
  190.  
  191.     <!-- Union All statement                                                  -->
  192.     <xsl:template match="UnionAll">
  193.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  194.             (
  195.         </xsl:if>
  196.             <xsl:call-template name="print-children-list">
  197.                 <xsl:with-param name="operator" select="' UNION ALL '"/>
  198.             </xsl:call-template>
  199.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  200.             )
  201.         </xsl:if>
  202.     </xsl:template>
  203.  
  204.     <!-- Top clause                                                       -->
  205.     <xsl:template match="Top">
  206.         TOP <xsl:value-of select="."/><xsl:text> </xsl:text>
  207.     </xsl:template>
  208.  
  209.     <!-- Select statement                                                 -->
  210.     <xsl:template match="Select">
  211.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert' and name(..) != 'Union' and name(..) != 'UnionAll'">
  212.             (
  213.         </xsl:if>
  214.         SELECT <xsl:apply-templates select="./Top"/>
  215.             <xsl:apply-templates select="./Distinct"/>
  216.             <xsl:apply-templates select="./ColumnExpressions"/>
  217.             <xsl:apply-templates select="./Sources"/>
  218.             <xsl:apply-templates select="./Where"/>
  219.             <xsl:apply-templates select="./GroupBy"/>
  220.             <xsl:apply-templates select="./OrderBy"/>
  221.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert' and name(..) != 'Union' and name(..) != 'UnionAll'">
  222.             )
  223.         </xsl:if>
  224.     </xsl:template>
  225.  
  226.     <!-- Update statement                                                 -->
  227.     <xsl:template match="Update">
  228.         UPDATE <xsl:apply-templates select="./Target"/>
  229.             <xsl:apply-templates select="./Where"/>
  230.     </xsl:template>
  231.  
  232.     <!-- Insert statement                                                 -->
  233.     <xsl:template match="Insert">
  234.         INSERT INTO <xsl:apply-templates select="./Target"/>
  235.         <xsl:apply-templates select="./Select"/>
  236.     </xsl:template>
  237.  
  238.     <!-- Delete statement                                                 -->
  239.     <xsl:template match="Delete">
  240.         DELETE FROM <xsl:apply-templates select="./Target"/>
  241.             <xsl:apply-templates select="./Where"/>
  242.     </xsl:template>
  243.  
  244.     <!-- Drop statement                                                   -->
  245.     <xsl:template match="Drop">
  246.         DROP <xsl:apply-templates select="./*"/>
  247.     </xsl:template>
  248.  
  249.     <!-- Create statement                                                 -->
  250.     <xsl:template match="Create">
  251.         CREATE <xsl:apply-templates select="./*[1]"/>
  252.         <xsl:choose>
  253.             <xsl:when test="name(./*[1]) = 'Table'">( <xsl:apply-templates select="./*[2]"/> )</xsl:when>
  254.         </xsl:choose>
  255.     </xsl:template>
  256.  
  257.     <!-- Remote query (OPENROWSET)                                        -->
  258.     <xsl:template match="RemoteQuery">
  259.         OPENROWSET
  260.         (
  261.             <xsl:call-template name="quote-string"><xsl:with-param name="string" select="./Provider"/></xsl:call-template>,
  262.             <xsl:choose>
  263.                 <xsl:when test="./DataSource">
  264.                     <xsl:call-template name="quote-string"><xsl:with-param name="string" select="./DataSource"/></xsl:call-template>;<xsl:call-template name="quote-string"><xsl:with-param name="string" select="./UserName"/></xsl:call-template>;<xsl:call-template name="quote-string"><xsl:with-param name="string" select="./Password"/></xsl:call-template>,
  265.                 </xsl:when>
  266.                 <xsl:otherwise>
  267.                     <xsl:call-template name="quote-string"><xsl:with-param name="string" select="./ConnectionString"/></xsl:call-template>,
  268.                 </xsl:otherwise>
  269.             </xsl:choose>
  270.             <xsl:call-template name="quote-string"><xsl:with-param name="string" select="./*[last()]"/></xsl:call-template>
  271.         )
  272.     </xsl:template>
  273.  
  274.     <xsl:template match="Distinct">
  275.         DISTINCT
  276.     </xsl:template>
  277.  
  278.     <xsl:template match="As">
  279.         <xsl:apply-templates select="./*[1]"/> AS <xsl:apply-templates select="./*[2]"/>
  280.     </xsl:template>
  281.  
  282.     <xsl:template match="Sources">
  283.         FROM <xsl:call-template name="print-children-list"/>
  284.     </xsl:template>
  285.  
  286.     <xsl:template match="ColumnDefinitions">
  287.         <xsl:call-template name="print-children-list"/>
  288.     </xsl:template>
  289.  
  290.     <xsl:template match="GroupBy">
  291.         GROUP BY <xsl:call-template name="print-children-list"/>
  292.     </xsl:template>
  293.  
  294.     <xsl:template match="OrderBy">
  295.         ORDER BY <xsl:call-template name="print-children-list"/>
  296.     </xsl:template>
  297.  
  298.     <xsl:template match="Where">
  299.         WHERE <xsl:apply-templates select="./*"/>
  300.     </xsl:template>
  301.  
  302.     <xsl:template match="Having">
  303.         HAVING <xsl:apply-templates select="./*"/>
  304.     </xsl:template>
  305.  
  306.     <xsl:template match="ColumnExpressions">
  307.         <xsl:call-template name="print-children-list"/>
  308.     </xsl:template>
  309.  
  310.     <xsl:template match="ColumnUpdates">
  311.         <xsl:call-template name="print-children-list"/>
  312.     </xsl:template>
  313.  
  314.     <xsl:template match="Assign">
  315.         <xsl:apply-templates select="./*[1]"/>=<xsl:apply-templates select="./*[2]"/>
  316.     </xsl:template>
  317.  
  318.     <xsl:template match="Insert/Target">
  319.         <xsl:apply-templates select="./Table"/>
  320.         (
  321.             <xsl:call-template name="print-list">
  322.                 <xsl:with-param name="value-node" select="./ColumnUpdates/*/*[1]"/>
  323.             </xsl:call-template>
  324.         )
  325.         <xsl:if test="./*[2]/Assign">
  326.             VALUES
  327.             (
  328.                 <xsl:call-template name="print-list">
  329.                     <xsl:with-param name="value-node" select="./ColumnUpdates/*/*[2]"/>
  330.                 </xsl:call-template>
  331.             )
  332.         </xsl:if>
  333.     </xsl:template>
  334.  
  335.     <xsl:template match="Update/Target">
  336.         <xsl:apply-templates select="./Table"/>
  337.         SET <xsl:apply-templates select="./ColumnUpdates"/>
  338.     </xsl:template>
  339.  
  340.     <xsl:template match="Delete/Target">
  341.         <xsl:apply-templates select="./Table"/>
  342.     </xsl:template>
  343.  
  344.     <xsl:template match="Insert/Target/ColumnUpdates/Assign/SQLColumn[1]">
  345.         <!-- The table name is not printed for LHS of assignments in insert -->
  346.         <xsl:apply-templates select="./Column"/>
  347.     </xsl:template>
  348.  
  349.     <xsl:template match="Create/ColumnDefinitions/SQLColumn">
  350.         <xsl:apply-templates select="./Column"/>
  351.         <xsl:apply-templates select="./Type"/>
  352.         <xsl:apply-templates select="./Usage"/>
  353.     </xsl:template>
  354.  
  355.     <xsl:template match="SQLColumn">
  356.         <xsl:variable name="table">
  357.             <xsl:if test="name(..)!='Count' or name(./Column/*[1]) != 'Asterisk'"><xsl:apply-templates select="./Table"/></xsl:if>
  358.         </xsl:variable>
  359.         <xsl:variable name="column">
  360.             <xsl:apply-templates select="./Column"/>
  361.         </xsl:variable>
  362.         <xsl:choose>
  363.             <xsl:when test="$table = ''">
  364.                 <xsl:value-of select="$column"/>
  365.             </xsl:when>
  366.             <xsl:otherwise>
  367.                 <xsl:value-of select="concat($table,'.', $column)"/>
  368.             </xsl:otherwise>
  369.         </xsl:choose>
  370.     </xsl:template>
  371.  
  372.     <xsl:template match="Create/Database|Drop/Database">
  373.         DATABASE <xsl:apply-templates select="./Name"/>
  374.     </xsl:template>
  375.  
  376.     <xsl:template match="Table">
  377.         <xsl:call-template name="build-quoted-schema-object"/>
  378.     </xsl:template>
  379.  
  380.     <xsl:template match="Create/Table|Drop/Table">
  381.         TABLE <xsl:call-template name="build-quoted-schema-object"/>
  382.     </xsl:template>
  383.  
  384.     <xsl:template match="View">
  385.         <xsl:call-template name="build-quoted-schema-object"/>
  386.     </xsl:template>
  387.  
  388.     <xsl:template match="Drop/View">
  389.         VIEW <xsl:call-template name="build-quoted-schema-object"/>
  390.     </xsl:template>
  391.  
  392.     <xsl:template match="Index">
  393.         <xsl:apply-templates select="./Name"/>
  394.     </xsl:template>
  395.  
  396.     <xsl:template match="Drop/Index">
  397.         INDEX <xsl:apply-templates select="./Name"/>
  398.     </xsl:template>
  399.  
  400.     <xsl:template match="Column">
  401.         <xsl:apply-templates select="./Asterisk"/>
  402.         <xsl:apply-templates select="./Name"/>
  403.     </xsl:template>
  404.  
  405.     <xsl:template match="Table/Name|View/Name|Index/Name|Column/Name|Database/Name|Schema">
  406.         <xsl:call-template name="quote-identifier"/>
  407.     </xsl:template>
  408.  
  409.     <xsl:template match="Usage">
  410.         <xsl:variable name="usage"><xsl:value-of select="."/></xsl:variable>
  411.         <xsl:choose>
  412.             <xsl:when test="$usage = 'Key'">    primary key   </xsl:when>
  413.         </xsl:choose>
  414.     </xsl:template>
  415.  
  416.     <xsl:template match="OpaqueExpression">
  417.         <xsl:if test="name(..) = 'As' and name(../..) = 'Sources'">
  418.             (
  419.         </xsl:if>
  420.         <xsl:value-of select="."/>
  421.         <xsl:if test="name(..) = 'As' and name(../..) = 'Sources'">
  422.             )
  423.         </xsl:if>
  424.     </xsl:template>
  425.  
  426.     <xsl:template match="OrderExpression">
  427.         <xsl:apply-templates select="./*[1]"/>
  428.         <xsl:apply-templates select="./Asc"/>
  429.         <xsl:apply-templates select="./Desc"/>
  430.     </xsl:template>
  431.  
  432.     <xsl:template match="Asc">
  433.         ASC
  434.     </xsl:template>
  435.  
  436.     <xsl:template match="Desc">
  437.         DESC
  438.     </xsl:template>
  439.  
  440.     <!-- Print values: ? for parametric queries and convert expressions
  441.          for non-parametric queries                                       -->
  442.     <xsl:template match="Parameter">
  443.         <xsl:choose>
  444.             <xsl:when test="$UseParams = 'yes' or $UseParams = 'nosubsel'">
  445.                 <xsl:choose>
  446.                     <xsl:when test="./@ParamName">
  447.                         @<xsl:value-of select="./@ParamName"/>
  448.                     </xsl:when>
  449.                     <xsl:otherwise>
  450.                         ?
  451.                     </xsl:otherwise>
  452.                 </xsl:choose>
  453.             </xsl:when>
  454.             <xsl:otherwise>
  455.                 <xsl:call-template name="print-non-parametric-parameter-ref">
  456.                     <xsl:with-param name="parameter-reference" select="."/>
  457.                 </xsl:call-template>
  458.             </xsl:otherwise>
  459.         </xsl:choose>
  460.     </xsl:template>
  461.  
  462.     <!-- DatePart                                                         -->
  463.     <xsl:template match="DatePart">
  464.         DATEPART( <xsl:apply-templates select="./*[1]"/> , <xsl:apply-templates select="./*[2]"/> )
  465.     </xsl:template>
  466.  
  467.     <!-- DatePartSpec                                                     -->
  468.     <xsl:template match="DatePartSpec">
  469.         <xsl:variable name="dps-val"><xsl:value-of select="normalize-space(./text())"/></xsl:variable>
  470.         <xsl:choose>
  471.             <xsl:when test="$dps-val = 'Year'">        year        </xsl:when>
  472.             <xsl:when test="$dps-val = 'Quarter'">     quarter     </xsl:when>
  473.             <xsl:when test="$dps-val = 'Month'">       month       </xsl:when>
  474.             <xsl:when test="$dps-val = 'DayOfYear'">   dayofyear   </xsl:when>
  475.             <xsl:when test="$dps-val = 'Day'">         day         </xsl:when>
  476.             <xsl:when test="$dps-val = 'Week'">        week        </xsl:when>
  477.             <xsl:when test="$dps-val = 'DayOfWeek'">   weekday     </xsl:when>
  478.             <xsl:when test="$dps-val = 'Hour'">        hour        </xsl:when>
  479.             <xsl:when test="$dps-val = 'Minute'">      minute      </xsl:when>
  480.             <xsl:when test="$dps-val = 'Second'">      second      </xsl:when>
  481.             <xsl:when test="$dps-val = 'Millisecond'"> millisecond </xsl:when>
  482.         </xsl:choose>
  483.     </xsl:template>
  484.  
  485.     <!-- Asterisk                                                         -->
  486.     <xsl:template match="Asterisk">*</xsl:template>
  487.  
  488.     <!-- Count/Min/Max/Sum                                                -->
  489.     <xsl:template match="Min|Max|Sum">
  490.         <xsl:variable name="function">
  491.             <xsl:choose>
  492.                 <xsl:when test="name()='Min'"> MIN </xsl:when>
  493.                 <xsl:when test="name()='Max'"> MAX </xsl:when>
  494.                 <xsl:when test="name()='Sum'"> SUM </xsl:when>
  495.             </xsl:choose>
  496.         </xsl:variable>
  497.         <xsl:value-of select="$function"/>( <xsl:apply-templates select="./*[1]"/> )
  498.     </xsl:template>
  499.  
  500.     <xsl:template match="Count">
  501.         COUNT ( <xsl:apply-templates select="./*[1]"/> <xsl:apply-templates select="./*[2]"/> )
  502.     </xsl:template>
  503.  
  504.     <!-- Binary expressions                                               -->
  505.     <!-- Equal/NotEqual/Greater/GreaterOrEqual/Less/LessOrEqual/In/And/Or/Plus/Minus/Divide/Multiply
  506.          expressions                                                      -->
  507.     <xsl:template match="Equal|NotEqual|Greater|GreaterOrEqual|Less|LessOrEqual|In|And|Or|Plus|Minus|Divide|Multiply">
  508.         <xsl:variable name="operator">
  509.             <xsl:choose>
  510.                 <xsl:when test="name()='Equal'">            =        </xsl:when>
  511.                 <xsl:when test="name()='NotEqual'">            <>    </xsl:when>
  512.                 <xsl:when test="name()='Greater'">            >        </xsl:when>
  513.                 <xsl:when test="name()='GreaterOrEqual'">    >=        </xsl:when>
  514.                 <xsl:when test="name()='Less'">                <    </xsl:when>
  515.                 <xsl:when test="name()='LessOrEqual'">        <=    </xsl:when>
  516.                 <xsl:when test="name()='In'">                IN        </xsl:when>
  517.                 <xsl:when test="name()='And'">                AND        </xsl:when>
  518.                 <xsl:when test="name()='Or'">                OR        </xsl:when>
  519.                 <xsl:when test="name()='Plus'">                +        </xsl:when>
  520.                 <xsl:when test="name()='Minus'">            -        </xsl:when>
  521.                 <xsl:when test="name()='Divide'">            /        </xsl:when>
  522.                 <xsl:when test="name()='Multiply'">            *        </xsl:when>
  523.             </xsl:choose>
  524.         </xsl:variable>
  525.         (
  526.             <xsl:call-template name="print-children-list">
  527.                 <xsl:with-param name="operator" select="$operator"/>
  528.             </xsl:call-template>
  529.         )
  530.     </xsl:template>
  531.  
  532.     <!-- Postfix unary expressions                                        -->
  533.     <!-- IsNull
  534.          expressions                                                      -->
  535.     <xsl:template match="IsNull">
  536.         <xsl:variable name="operator">
  537.             <xsl:choose>
  538.                 <xsl:when test="name()='IsNull'">            IS NULL        </xsl:when>
  539.             </xsl:choose>
  540.         </xsl:variable>
  541.         (
  542.             <xsl:apply-templates select="./*[1]"/>
  543.             <xsl:value-of select="$operator"/>
  544.         )
  545.     </xsl:template>
  546.  
  547.     <!-- Types                                                            -->
  548.     <xsl:template match="Type">
  549.         <xsl:variable name="type-val"><xsl:value-of select="normalize-space(./text())"/></xsl:variable>
  550.         <xsl:choose>
  551.             <xsl:when test="$type-val = 'DBTYPE_BSTR'">    nvarchar     </xsl:when>
  552.             <xsl:when test="$type-val = 'DBTYPE_WSTR'">    nvarchar     </xsl:when>
  553.             <xsl:when test="$type-val = 'DBTYPE_STR'">     varchar      </xsl:when>
  554.             <xsl:when test="$type-val = 'DBTYPE_BOOL'">    bit          </xsl:when>
  555.             <xsl:when test="$type-val = 'DBTYPE_I1'">      tinyint      </xsl:when>
  556.             <xsl:when test="$type-val = 'DBTYPE_I2'">      smallint     </xsl:when>
  557.             <xsl:when test="$type-val = 'DBTYPE_I4'">      int          </xsl:when>
  558.             <xsl:when test="$type-val = 'DBTYPE_I8'">      bigint       </xsl:when>
  559.             <xsl:when test="$type-val = 'DBTYPE_UI1'">     tinyint      </xsl:when>
  560.             <xsl:when test="$type-val = 'DBTYPE_UI2'">     smallint     </xsl:when>
  561.             <xsl:when test="$type-val = 'DBTYPE_UI4'">     int          </xsl:when>
  562.             <xsl:when test="$type-val = 'DBTYPE_UI8'">     bigint       </xsl:when>
  563.             <xsl:when test="$type-val = 'DBTYPE_R4'">      real         </xsl:when>
  564.             <xsl:when test="$type-val = 'DBTYPE_R8'">      float        </xsl:when>
  565.             <xsl:when test="$type-val = 'DBTYPE_DATE'">    datetime     </xsl:when>
  566.             <xsl:when test="$type-val = 'DBTYPE_DBTIMESTAMP'">    datetime     </xsl:when>
  567.             <xsl:when test="$type-val = 'DBTYPE_CY'">      money        </xsl:when>
  568.             <xsl:when test="$type-val = 'DBTYPE_VARIANT'"> sql_variant  </xsl:when>
  569.             <xsl:when test="$type-val = 'DBTYPE_GUID'"> uniqueidentifier  </xsl:when>
  570.             <xsl:when test="$type-val = 'DBTYPE_ByteArray'"> varbinary  </xsl:when>
  571.             <xsl:when test="$type-val = 'DBTYPE_DECIMAL'"> decimal      </xsl:when>
  572.         </xsl:choose>
  573.         <xsl:apply-templates select="./Size"/>
  574.         <xsl:apply-templates select="./Precision"/>
  575.         <xsl:apply-templates select="./Scale"/>        
  576.     </xsl:template>
  577.  
  578.     <!-- Size (optional)                                                  -->
  579.     <xsl:template match="Size">
  580.     ( <xsl:value-of select="./text()"/> )
  581.     </xsl:template>
  582.     
  583.     <!-- Precision (optional)                                                  -->
  584.     <xsl:template match="Precision">
  585.     ( <xsl:value-of select="./text()"/>
  586.     </xsl:template>
  587.  
  588.     <!-- Scale (optional)                                                  -->
  589.     <xsl:template match="Scale">
  590.     , <xsl:value-of select="./text()"/> )
  591.     </xsl:template>
  592.     <!-- Cast                                                             -->
  593.     <xsl:template match="Cast">
  594.         CAST(<xsl:apply-templates select="./*[1]"/> AS <xsl:apply-templates select="./*[2]"/>)
  595.     </xsl:template>
  596.     
  597.     <!-- By default don't do anything                                     -->
  598.     <xsl:template match="*">
  599.     </xsl:template>
  600.  
  601.     <!-- Print a schema object                                               -->
  602.     <xsl:template name="build-quoted-schema-object"> 
  603.         <xsl:param name="schema-object-node" select="."/>
  604.  
  605.         <xsl:variable name="schema">
  606.             <xsl:apply-templates select="$schema-object-node/Schema"/>
  607.         </xsl:variable>
  608.         <xsl:variable name="table">
  609.             <xsl:apply-templates select="$schema-object-node/Name"/>
  610.         </xsl:variable>
  611.         <xsl:choose>
  612.             <xsl:when test="$schema = ''">
  613.                 <xsl:value-of select="$table"/>
  614.             </xsl:when>
  615.             <xsl:otherwise>
  616.                 <xsl:value-of select="concat($schema,'.', $table)"/>
  617.             </xsl:otherwise>
  618.         </xsl:choose>
  619.     </xsl:template>
  620.  
  621.     <!-- Convert an identifier to the OLEDB quotation form                -->
  622.     <xsl:template name="quote-identifier"> 
  623.         <xsl:param name="identifier" select="."/>
  624.  
  625.         <xsl:value-of select="$IdentifierStartQuotingCharacter"/>
  626.         <xsl:call-template name="normalize-entity-aux">
  627.             <xsl:with-param name="entity" select="$identifier"/>
  628.             <xsl:with-param name="end-quoting-char" select="$IdentifierEndQuotingCharacter"/>
  629.         </xsl:call-template>
  630.         <xsl:value-of select="$IdentifierEndQuotingCharacter"/>
  631.     </xsl:template>
  632.  
  633.     <!-- Convert a string to the string quotation form                    -->
  634.     <xsl:template name="quote-string"> 
  635.         <xsl:param name="string" select="."/>
  636.  
  637.         <xsl:value-of select="$StringStartQuotingCharacter"/>
  638.         <xsl:call-template name="normalize-entity-aux">
  639.             <xsl:with-param name="entity" select="$string"/>
  640.             <xsl:with-param name="end-quoting-char" select="$StringEndQuotingCharacter"/>
  641.         </xsl:call-template>
  642.         <xsl:value-of select="$StringEndQuotingCharacter"/>
  643.     </xsl:template>
  644.  
  645.     <!-- Convert an entity to the quotation form (recursive, aux)  by
  646.          duplicating the end quoting character                            -->
  647.     <xsl:template name="normalize-entity-aux"> 
  648.         <xsl:param name="entity"/>
  649.         <xsl:param name="end-quoting-char"/>
  650.  
  651.         <xsl:choose>
  652.             <xsl:when test="contains($entity, $end-quoting-char)">
  653.                 <xsl:value-of select="substring-before($entity, $end-quoting-char)"/>
  654.                 <xsl:value-of select="$end-quoting-char"/>
  655.                 <xsl:value-of select="$end-quoting-char"/>
  656.                 <xsl:call-template name="normalize-entity-aux">
  657.                     <xsl:with-param name="entity" select="substring-after($entity, $end-quoting-char)"/>
  658.                     <xsl:with-param name="end-quoting-char" select="$end-quoting-char"/>
  659.                 </xsl:call-template>
  660.             </xsl:when>
  661.             <xsl:otherwise>
  662.                 <xsl:value-of select="$entity"/>
  663.             </xsl:otherwise>
  664.         </xsl:choose>
  665.     </xsl:template>
  666.  
  667.     <!-- Print the children list                                          -->
  668.     <xsl:template name="print-children-list">
  669.         <xsl:param name="operator" select="','"/>
  670.         
  671.         <xsl:call-template name="print-list">
  672.             <xsl:with-param name="value-node" select="./*"/>
  673.             <xsl:with-param name="operator" select="$operator"/>
  674.         </xsl:call-template>
  675.     </xsl:template>
  676.  
  677.     <!-- Print a list                                                     -->
  678.     <xsl:template name="print-list">
  679.         <xsl:param name="operator" select="','"/>
  680.         <xsl:param name="value-node" select="."/>
  681.  
  682.         <xsl:for-each select="$value-node">
  683.             <xsl:apply-templates select="."/>
  684.             <xsl:if test="position()!=last()">
  685.                 <xsl:value-of select="$operator"/>
  686.             </xsl:if>
  687.         </xsl:for-each>
  688.     </xsl:template>
  689.  
  690.     <!-- Get the value of a parameter ref for the query                   -->
  691.     <xsl:template name="print-non-parametric-parameter-ref">
  692.         <xsl:param name="parameter-reference"/>
  693.  
  694.         <xsl:variable name="reference"><xsl:value-of select="$parameter-reference/@ref"/></xsl:variable>
  695.         <xsl:call-template name="print-non-parametric-parameter">
  696.             <xsl:with-param name="parameter" select="/Statement/Parameters/Parameter[@id=$reference]"/>
  697.         </xsl:call-template>
  698.     </xsl:template>
  699.  
  700.     <!-- Get the value of a parameter ref for the query                   -->
  701.     <xsl:template name="print-non-parametric-parameter">
  702.         <xsl:param name="parameter"/>
  703.  
  704.         <xsl:variable name="db-type"><xsl:value-of select="$parameter/@DBTYPE"/></xsl:variable>
  705.         <xsl:variable name="value"><xsl:value-of select="$parameter/text()"/></xsl:variable>
  706.         <xsl:choose>
  707.             <xsl:when test="$db-type = 'DBTYPE_BSTR'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  708.             <xsl:when test="$db-type = 'DBTYPE_WSTR'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  709.             <xsl:when test="$db-type = 'DBTYPE_STR'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  710.             <xsl:when test="$db-type = 'DBTYPE_BOOL'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS bit)</xsl:when>
  711.             <xsl:when test="$db-type = 'DBTYPE_I1'"><xsl:value-of select="$value"/></xsl:when>
  712.             <xsl:when test="$db-type = 'DBTYPE_I2'"><xsl:value-of select="$value"/></xsl:when>
  713.             <xsl:when test="$db-type = 'DBTYPE_I4'"><xsl:value-of select="$value"/></xsl:when>
  714.             <xsl:when test="$db-type = 'DBTYPE_I8'"><xsl:value-of select="$value"/></xsl:when>
  715.             <xsl:when test="$db-type = 'DBTYPE_UI1'"><xsl:value-of select="$value"/></xsl:when>
  716.             <xsl:when test="$db-type = 'DBTYPE_UI2'"><xsl:value-of select="$value"/></xsl:when>
  717.             <xsl:when test="$db-type = 'DBTYPE_UI4'"><xsl:value-of select="$value"/></xsl:when>
  718.             <xsl:when test="$db-type = 'DBTYPE_UI8'"><xsl:value-of select="$value"/></xsl:when>
  719.             <xsl:when test="$db-type = 'DBTYPE_R4'"><xsl:value-of select="$value"/></xsl:when>
  720.             <xsl:when test="$db-type = 'DBTYPE_R8'"><xsl:value-of select="$value"/></xsl:when>
  721.             <xsl:when test="$db-type = 'DBTYPE_DATE'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS datetime)</xsl:when>
  722.             <xsl:when test="$db-type = 'DBTYPE_DBTIMESTAMP'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS datetime)</xsl:when>
  723.             <xsl:when test="$db-type = 'DBTYPE_CY'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS money)</xsl:when>
  724.             <xsl:when test="$db-type = 'DBTYPE_VARIANT'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  725.             <xsl:when test="$db-type = 'DBTYPE_GUID'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  726.             <xsl:when test="$db-type = 'DBTYPE_ByteArray'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  727.             <xsl:when test="$db-type = 'DBTYPE_DECIMAL'"><xsl:value-of select="$value"/></xsl:when>
  728.         </xsl:choose>
  729.     </xsl:template>
  730. </xsl:stylesheet>
  731.